import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
//mock
import { viteMockServe } from 'vite-plugin-mock'
//组件库
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    viteMockServe({
      mockPath: './src/mock'
    })
  ],
  resolve: {
    //别名的配置
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  //自动打开
  server: {
    open: true,
    //代理属性用于请求
    proxy: {
      '/api': {
        target: 'http://localhost:3002',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
    },
    //端口号
    // port: 8080,
  },
  build: {
    rollupOptions: {
      // 在这里可以设置 Rollup 的优化选项
      treeshake: true,
    },
  },
})
